package com.itheima.controller;

import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 套餐管理
 *
 * @Data 2020/10/17 12:39
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {


    //远程注入
    @Reference
    private SetmealService setmealService;


    /**
     * 获取套餐数据
     *
     * @return com.itheima.entity.Result
     */
    @RequestMapping("/getAllSetmeal.do")
    public Result getAllSetmeal() {
        try {
            List<Setmeal> list = setmealService.findAll();
            return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
    }

    /**
     * 获取套餐详细信息和他的关联信息（检查套餐，检查组，检查项）
     * @Parem id 检查套餐id
     * @return com.itheima.entity.Result
     */
    @RequestMapping("/findById")
    public Result findById1(Integer id) {
        try {
            Setmeal setmeal = setmealService.findById1(id);
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }


}
